package com.dy.course.service.impl;

import java.util.List;

import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.dy.course.common.BaseException;
import com.dy.course.common.BaseService;
import com.dy.course.common.Constant;
import com.dy.course.entity.ResourceInfo;
import com.dy.course.model.Resource;
import com.dy.course.service.IResourceService;

import tk.mybatis.mapper.entity.Example;

@Service
public class ResourceService extends BaseService<Resource> implements IResourceService {

	@Override
	public List<Resource> qureyResource(ResourceInfo info) {
		logger.info("【广告位】参数信息,info=" + JSON.toJSONString(info));
		Example example = new Example(Resource.class);
		example.createCriteria().andEqualTo("function",1);
		List<Resource> list = getMapper().selectByExample(example);
		if(list == null){
			logger.error("【】查询资源信息失败,info={}", info);
			throw new BaseException(Constant.Code.SELECT_ERROR,"暂时还没有广告位图片",null);
		}
		return list;
	}

	@Override
	public void upload(ResourceInfo info) {
		logger.info("【上传文件】参数信息,info=" + JSON.toJSONString(info));
		Resource resource = new Resource();
		BeanUtils.copyProperties(info, resource);
		getMapper().insertSelective(resource);
	}
}
